<?php

date_default_timezone_set('Asia/Shanghai');

use Pimple\Container;

// 应用初始化
(new \think\App())->console;

$config = config('plumber');
$redisConfig = $config['queue_redis_config'];
$plumberConfig = $config['worker_config'];


$options = [
    'app_name' => 'SendWorker',
    'queues' => [
        'queue_server_1' => [
            'type' => 'redis',
            'host' => $redisConfig['host'],
            'port' => $redisConfig['port'],
            'password' => $redisConfig['password'],
        ]
    ],
    'workers' => [
        [
            'class' => 'app\worker\SendWeChatWorker',
            'num' => $plumberConfig['send_message_tube_worker_num'],
            'queue' => 'queue_server_1',
            'topic' => $plumberConfig['send_message_tube'],
            'rate_limit' => 'wechat_rate_limit',
        ],
        [
            'class' => 'app\worker\AddSendLogWorker',
            'num' => $plumberConfig['add_send_log_num'],
            'queue' => 'queue_server_1',
            'topic' => $plumberConfig['add_send_log_tube'],
            'rate_limit' => 'wechat_rate_limit',
        ]
    ],
    'rate_limits' => [
        'wechat_rate_limit' => [
            'storage' => 'redis',
            'redis' => [
                'host' => $redisConfig['host'],
                'port' => $redisConfig['port'],
                'password' => $redisConfig['password'],
            ],
            'allowance' => $redisConfig['allowance'], // 限制每60秒最多消费1000个
            'period' => $redisConfig['period'],
        ]
    ],
//    'hour_limits' => [
//        'wechat_hour_limit' => ['start' => 23, 'end' => 23],
//    ],
    'log_path' => __DIR__ . '/../log/plumber.log',
    'pid_path' => __DIR__ . '/../tmp/plumber.pid',
];

class SendMessageContainer implements \Psr\Container\ContainerInterface
{
    public function get($id)
    {
        // TODO: Implement get() method.
    }

    public function has($id)
    {
        // TODO: Implement has() method.
    }
}

return [
    'options' => $options,
    'container' => new SendMessageContainer(),
];
